package com.changli03._list;


import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/*
* - 增
  add()

  addAll()

- 删

  reomve()
  remove(int index)

- 改
  set(int index , Collection eles)

- 查

  get (int index)

- 插
  add (int index)
  addAll(int index,Collection eles)

- 长度
  size()

- 遍历

  1. iterator()  迭代器 遍历

  2. 增强for循环
  3. 利用索引使用一般for循环
*
*
*
*
* */
public class ListTest {
    @Test
    public void test1() {


        List list = new ArrayList();
        //        add()
        list.add(1);
        list.add("222");

        list.add(new Person("sail",19));
//        addAll()
        Collection list2 = Arrays.asList(1,2,3);
        list.addAll(list2);

//        remove()
        list.remove(2);
//        list.remove(2);
        System.out.println(list);
//        list.removeAll(list2);
        System.out.println(list);

        System.out.println(list.size());
        //set(int index,Object o )
        list.set(0,2);
        System.out.println(list);
        System.out.println(list.get(3));


        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));

        }
    }

}
class Person {
    String name;
    int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}